#coding=utf-8
import os.path

def error(msg):
    print "ERROR:" + msg

def create_offer_map(target_dir, jobs_file, offer_map_file_name, offer_file):
    jobs_file_path = target_dir+jobs_file

    map_file_path = target_dir + offer_map_file_name

    if not os.path.exists(jobs_file_path):
        error("%s不存在" % jobs_file_path)

    fo = open(jobs_file_path)

    fw = open(map_file_path, 'wb')

    for line in fo:
        line = line.strip()
        elements = line.split()
        if len(elements) == 0:
            continue

        industry_name = elements[0]

        job_name = elements[1]

        map = []
        if industry_name and job_name:
            map.append(industry_name)
            map.append(job_name)
        else:
            continue

        map.append('录用信')

        map.append(offer_file)

        fw.write(' '.join(map) + '\n')


    fo.close()
    fw.close()


if __name__ == '__main__':
    target_dirs = ['Contract/catering/', 'Contract/internet/', 'Contract/culture/', 'Contract/cloth/',
                   'Contract/education/', 'Contract/retail/', 'Contract/travel/', 'Contract/construction/',
                   'Contract/finance/', 'Contract/science/', 'Contract/humanResource/']

    for dir in target_dirs:
        create_offer_map(dir, 'category_map.txt', 'offer_map.txt', 'offer.xml')


